package reese.think_in_java.java_21_thread;

/**
 * ***********************************************************
 *
 * @类名 : reese.think_in_java.java_21_thread.类名
 * @DESCRIPTION : 这家伙太懒啥都没写
 * @AUTHOR :  一个风情万种的男子
 * @DATE : 2016/6/2
 * ***********************************************************
 */

class DualSynch{
    private Object syncObject = new Object();
    public synchronized void f(){
        for (int i=0;i<5;i++){
            System.out.println("f() do");
            Thread.yield(); //yield 有放弃的意思
        }
    }

    public void g(){
        synchronized (syncObject){
            for (int i=0;i<5;i++){
                System.out.println("g() do");
                Thread.yield(); //yield 有放弃的意思
            }

        }
    }
}
public class SyncObject {

    public static void main(String[] args) {
        final DualSynch dualSynch = new DualSynch();
        new Thread(){
            @Override
            public void run() {
                dualSynch.f();
            }
        }.start();
        dualSynch.g();
    }

}
